package utilities.display.shapes;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;

//import utilities.convenience.Positioned;
import utilities.display.iface.Drawable;

/**
 * 
 * @author CoconutTank
 *
 */
public class DrawShape implements Drawable //, Positioned
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -5952001837262369165L;

	/**
	 * 
	 */
	protected Color myLineColor = null;
	
	/**
	 * 
	 */
	protected Stroke myLineStyle = null;
	
	/**
	 * 
	 */
	protected Composite myLineComposite = null;
	
	/**
	 * 
	 */
	protected Color myFillColor = null;
	
	/**
	 * 
	 */
	protected Composite myFillComposite = null;
	
	/**
	 * 
	 */
	protected Shape myShape;
	
	/**
	 * 
	 * @param s
	 * @param lineColor
	 * @param stroke
	 * @param lineComposite TODO
	 * @param fillColor
	 * @param fillComposite TODO
	 */
	public DrawShape(Shape s, 
					 Color lineColor, Stroke stroke, Composite lineComposite, 
					 Color fillColor, Composite fillComposite)
	{
		myShape = s;
		
		myLineColor = lineColor;
		myLineStyle = stroke;
		myFillColor = fillColor;
		
		myLineComposite = lineComposite != null ? lineComposite : AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
		myFillComposite = fillComposite != null ? fillComposite : AlphaComposite.getInstance(AlphaComposite.SRC, 1.0f);
	}
	
	/**
	 * 
	 * @return
	 */
	public final Color getFillColor() { return myFillColor; };
	
	/**
	 * 
	 * @param c
	 */
	public final void setFillColor(Color c) { myFillColor = c; };
	
	/**
	 * 
	 * @return
	 */
	public final Color getLineColor() { return myLineColor; };
	
	/**
	 * 
	 * @param c
	 */
	public final void setLineColor(Color c) { myLineColor = c; };
	
	/**
	 * 
	 * @return
	 */
	public final Stroke getLineStyle() { return myLineStyle; }
	
	/**
	 * 
	 * @param s
	 */
	public final void setLineStyle(Stroke s) { myLineStyle = s; }
	
	/**
	 * 
	 * @return
	 */
	public Shape getShape() { return myShape; }
	
	public void drawMe(Graphics g)
	{
		// Don't do anything if there's nothing to draw
		if(myShape == null) return;

		Graphics2D g2 = (Graphics2D) g;

		// Get previous settings...
		Color c = g2.getColor();
		Stroke s = g2.getStroke();
		Composite a = g2.getComposite();
		
		// Draw me now!!
		
		// Fill portion...
		if(myFillColor != null)
		{
			g2.setComposite(myFillComposite);
			g2.setColor(myFillColor);
			g2.fill(myShape);
		}
		
		// Line portion...
		if(myLineColor != null && myLineStyle != null)
		{
			g2.setComposite(myLineComposite);
			g2.setColor(myLineColor);
			g2.setStroke(myLineStyle);
			g2.draw(myShape);
		}
		
		// Restore previous settings...
		g2.setColor(c);
		g2.setStroke(s);
		g2.setComposite(a);
	}
}
